<template>
    <div class="container">
        <h6><b class="square"></b> 相关帖子</h6>
        <!-- 帖子列表 -->
        <ul class="list-unstyled mt-4">
            <li class="media pb-3 pt-3 mb-3 border-bottom" v-for="(item,i) in discussPosts" :key="i">
                <img @click="toRouter(item.user.id)" :src="item.user.photo" class="mr-4 rounded-circle user-header" alt="用户头像">
                <div class="media-body">
                    <h6 class="mt-0 mb-3">
                        <a :href="'/discussdetail'+item.discussPost.id" v-html = "item.discussPost.title"></a>
                    </h6>
                    <div class="mb-3" v-html = "item.discussPost.content">
                    </div>
                    <div class="text-muted font-size-12">
                        <u class="mr-3">{{item.user.name}}</u> 发布于 <b>{{item.discussPost.createTime | datatime}}</b>
                        <ul class="d-inline float-right">
                            <li class="d-inline ml-2">赞 {{item.likeCount}}</li>
                            <li class="d-inline ml-2">|</li>
                            <li class="d-inline ml-2">回复 {{item.discussPost.commentCount}}</li>
                        </ul>
                    </div>
                </div>
            </li>																			
        </ul>
        <!-- 分页 -->
        <pagination ref="pagination" v-bind:list="getlist" v-bind:itemCount="8"></pagination>
    </div>
</template>

<script>
import Pagination from "@/components/pagination";
export default {
    name:'search',
    data(){
        return{
          discussPosts:[],
            searchMsg:''
        }
    },
    components: {Pagination},
    created(){
        this.searchMsg =  this.$route.params.searchMsg
    },
    mounted(){
        this.getlist(1)
    },
    methods:{
        //获取查询数据
        getlist(page){
            
            console.log(this.searchMsg)
            // let _this = this;
            this.$ajax.post(process.env.VUE_APP_SERVER + '/business/web/search/'+this.searchMsg, {
                page: page,
                size: this.$refs.pagination.size,
            }).then((response)=>{
                console.log("查询帖子详情结果：", response);
                this.discussPosts = response.data.content.map.discussPosts;
                this.$refs.pagination.render(page, response.data.content.total);
            })
        },
        //跳转路由
        toRouter(id){
            this.$router.push({
                path:"/profile/" + id,
                name:"profile"
            })
        }
    }
}
</script>

<style lang="scss" scoped>
    @import '@/assets/style/css/global.scss';
    @import '@/assets/style/css/letter.scss';
    ::v-deep em{
      font-style: normal;
      color: red;
    }

</style>